package com.object.utils;

import net.sf.cglib.beans.BeanCopier;
import org.apache.poi.ss.formula.functions.T;

import java.util.ArrayList;
import java.util.List;

public class BeanCopierUtil
{
    public static <T> T copyObject(T val1)
    {
        BeanCopier copier = BeanCopier.create(val1.getClass(), val1.getClass(), false);
        Object newInstance = null;
        try {
            newInstance = val1.getClass().newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        T t = (T) newInstance;
        copier.copy(val1, t, null);
        return t;
    }

    public static <T> T copyObject(T val1, T val2)
    {
        BeanCopier copier = BeanCopier.create(val1.getClass(), val1.getClass(), false);
        copier.copy(val1, val2, null);
        return val2;
    }

}
